package com.vanrui.pcp.autocode.utils;

public class StringUtilu {
	
	/**
	 * 将字符串的首字符大写
	 * @param str
	 * @return
	 */
	public static String getFirstUpperStr(String str){
		if(str == null){
			return null;
		}
		if(str.trim().length() == 0){
			return str;
		}
		char[] array = str.toCharArray();
		array[0] = Character.toUpperCase(array[0]);
		return String.copyValueOf(array);
	}
	
	/**
	 * 将字符串中的下划线去掉，并生成驼峰形式的标示符字符串
	 * @param str
	 * @return
	 */
	public static String getStrWithoutUnderline(String str){
		if(str == null){
			return null;
		}
		if(str.trim().length() == 0){
			return str;
		}
		char[] array = str.toCharArray();
		char[] _array = new char[array.length];
		int _i = 0;
		boolean isUnderline = false;
		for (int i = 0; i < array.length; i++) {
			if(i != 0){
				if(array[i] == '_'){
					isUnderline = true;
					continue;
				}
			}
			if(isUnderline){
				_array[_i] = Character.toUpperCase(array[i]);
				isUnderline = false;
			}else{
				_array[_i] = array[i];
			}
			_i++;
		}
		return String.valueOf(_array, 0, _i);
	}

}
